package com.devicemantra.coordinate.dataobjects;

import javax.jdo.annotations.*;

import org.apache.commons.io.IOUtils;

import java.util.*;

import com.google.appengine.api.datastore.Blob;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable ="true")
public class Logo 
{
	@PrimaryKey
    @Persistent (valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key mKey;
	
	 @Persistent
	 private String mName;

   
	@Persistent
    private String mContentType;

    @Persistent(defaultFetchGroup="true")
    private Blob mImage; 
    
    @Persistent(defaultFetchGroup="true")
    private String mFileName; 

    public Logo() { }
    
    public Logo(String pName , String pContentType, Blob pImage ) {
    	mContentType = pContentType; 
        mFileName = mName = pName;
        //  mKey = KeyFactory.createKey(Logo.class.getSimpleName(), UUID.randomUUID().toString());
        mImage = pImage;
        System.out.println("Logo created with :" + mContentType + pName + pImage.getClass());
    }
    
    public Logo(String pName , String pContentType, byte[] pByteArray ) {
    	mContentType = pContentType; 
        mFileName = mName = pName;
        //  mKey = KeyFactory.createKey(Logo.class.getSimpleName(), UUID.randomUUID().toString());
        mImage = new Blob(pByteArray);
        System.out.println("Logo created with :" + mContentType + pName );
    }

    // JPA getters and setters and empty contructor
    // ...
    public String getName() {
		return mName;
	}
	public void setName(String pName) {
		mName = pName;
	}
	public String getContentType() {
		return mContentType;
	}
	public void setContentType(String pContentType) {
		mContentType = pContentType;
	}
	
  public Blob getImage() {
		return mImage;
	}
	public void setImage(Blob pImage) {
		mImage = pImage;
	}  
	
	public String getKey()
	{
		return KeyFactory.keyToString(mKey);
	}
	
	public String getUrl()
	{
		System.out.println("getUrl() returning " + "/icons/" + mName);
		return "/icons/" + mName;
	}
}
